翻訳と辞書
Words near each other
・ Injector (disambiguation)
・ Injedu
・ Injeh
・ Injeolmi
・ Injera
・ Injevar
・ Injevo
・ Inji
・ Inji Aflatoun
・ Inji Hanimefendi
・ Injibara
・ Injikollai
・ Injil District
・ Injil, Afghanistan
・ Injimedu
Initialization-on-demand holder idiom
・ Initialized fractional calculus
・ Initialized sign
・ Initials B.B.
・ Initiate
・ Initiate (album)
・ Initiate (Nels Cline Singers album)
・ Initiate's Trial
・ Initiating Prosperity
・ Initiating Representative
・ Initiation
・ Initiation (chemistry)
・ Initiation (Course of Empire album)
・ Initiation (disambiguation)
・ Initiation (film)


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Initialization-on-demand holder idiom : ウィキペディア英語版
Initialization-on-demand holder idiom
In software engineering, the Initialization on Demand Holder (design pattern) idiom is a lazy-loaded singleton. In all versions of Java, the idiom enables a safe, highly concurrent lazy initialization with good performance.〔The Double Checked Locking Idiom does not work correctly in Java versions prior to 1.5.〕

public class Something
public static Something getInstance()
}

The implementation of the idiom relies on the initialization phase of execution within the Java Virtual Machine (JVM) as specified by the Java Language Specification (JLS).〔See (12.4 of Java Language Specification ) for details.〕 When the class Something is loaded by the JVM, the class goes through initialization. Since the class does not have any static variables to initialize, the initialization completes trivially. The static class definition LazyHolder within it is ''not'' initialized until the JVM determines that LazyHolder must be executed. The static class LazyHolder is only executed when the static method getInstance is invoked on the class Something, and the first time this happens the JVM will load and initialize the LazyHolder class. The initialization of the LazyHolder class results in static variable INSTANCE being initialized by executing the (private) constructor for the outer class Something. Since the class initialization phase is guaranteed by the JLS to be serial, i.e., non-concurrent, no further synchronization is required in the static getInstance method during loading and initialization. And since the initialization phase writes the static variable INSTANCE in a serial operation, all subsequent concurrent invocations of the getInstance will return the same correctly initialized INSTANCE without incurring any additional synchronization overhead.
This gives a highly efficient thread-safe "singleton" cache, without synchronization overhead; benchmarking indicates it to be far faster than even uncontended synchronization.〔(【引用サイトリンク】url=http://literatejava.com/jvm/fastest-threadsafe-singleton-jvm/ )〕 However, the idiom is singleton-specific and not extensible to pluralities of objects (e.g. a map-based cache).
== Only One Chance To Initialize ==

Despite the elegance of this approach (first described by Pugh), any failure to initialize renders the class unusable which means the holder pattern can only be used when the programmer is certain the initialization will not fail. Example:

public class PughFail
private static class LazyHolder
public static Something getInstance()
}
public static void main(String[] args)
System.out.println("Second try");
try catch (Throwable t)
}
}

output:

First try
PughFail$Something called
EMULATING INIT FAILURE
java.lang.ExceptionInInitializerError
Second try
java.lang.NoClassDefFoundError: Could not initialize class PughFail$Something$LazyHolder


抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Initialization-on-demand holder idiom」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.